<?php

/**
 * This is the model class for table "produk".
 *
 * The followings are the available columns in table 'produk':
 * @property string $KODE_PRODUK
 * @property string $ID_KATEGORI
 * @property integer $KODE_TOKO
 * @property string $NAMA_PRODUK
 * @property integer $HARGA
 * @property string $DESKRIPSI
 * @property string $GAMBAR_PRODUK
 * @property string $SIZE
 *
 * The followings are the available model relations:
 * @property DetailPemesanan[] $detailPemesanans
 * @property KategoriProduk $iDKATEGORI
 * @property Toko $kODETOKO
 * @property Whislist[] $whislists
 */
class Produk extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Produk the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'produk';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('KODE_PRODUK, NAMA_PRODUK, HARGA, DESKRIPSI, GAMBAR_PRODUK, SIZE', 'required'),
			array('KODE_TOKO, HARGA', 'numerical', 'integerOnly'=>true),
			array('KODE_PRODUK', 'length', 'max'=>8),
			array('ID_KATEGORI, SIZE', 'length', 'max'=>20),
			array('NAMA_PRODUK', 'length', 'max'=>30),
			array('DESKRIPSI', 'length', 'max'=>100),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('KODE_PRODUK, ID_KATEGORI, KODE_TOKO, NAMA_PRODUK, HARGA, DESKRIPSI, GAMBAR_PRODUK, SIZE', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'detailPemesanans' => array(self::HAS_MANY, 'DetailPemesanan', 'KODE_PRODUK'),
			'iDKATEGORI' => array(self::BELONGS_TO, 'KategoriProduk', 'ID_KATEGORI'),
			'kODETOKO' => array(self::BELONGS_TO, 'Toko', 'KODE_TOKO'),
			'whislists' => array(self::HAS_MANY, 'Whislist', 'KODE_PRODUK'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'KODE_PRODUK' => 'Kode Produk',
			'ID_KATEGORI' => 'Id Kategori',
			'KODE_TOKO' => 'Kode Toko',
			'NAMA_PRODUK' => 'Nama Produk',
			'HARGA' => 'Harga',
			'DESKRIPSI' => 'Deskripsi',
			'GAMBAR_PRODUK' => 'Gambar Produk',
			'SIZE' => 'Size',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('KODE_PRODUK',$this->KODE_PRODUK,true);
		$criteria->compare('ID_KATEGORI',$this->ID_KATEGORI,true);
		$criteria->compare('KODE_TOKO',$this->KODE_TOKO);
		$criteria->compare('NAMA_PRODUK',$this->NAMA_PRODUK,true);
		$criteria->compare('HARGA',$this->HARGA);
		$criteria->compare('DESKRIPSI',$this->DESKRIPSI,true);
		$criteria->compare('GAMBAR_PRODUK',$this->GAMBAR_PRODUK,true);
		$criteria->compare('SIZE',$this->SIZE,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}